var _n55;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$Loader = require("Loader");
var s = cc__importDefault($1$Loader);
var $1$zqcc_pageBase = require("zqcc_pageBase");
var c = cc__importDefault($1$zqcc_pageBase);
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $1$EventManager = require("EventManager");
var u = cc__importDefault($1$EventManager);
var $GameEventType = require("GameEventType");
var $1$userService = require("userService");
var d = cc__importDefault($1$userService);
var $1$gameListItemNew = require("gameListItemNew");
var h = cc__importDefault($1$gameListItemNew);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_gameListNew = function (t) {
  function _ctor() {
    // 调用t函数并获取上下文，若返回为null，则使用当前对象
    var context = null !== t && t.apply(this, arguments) || this;

    // 设置页面名称
    context.pageName = "更多游戏";

    // 初始化其他属性为null
    context.item = null;
    context.scrContent = null;
    context.changwanBtn = null;
    context.tips = null;
    context.listData = null;

    // 返回上下文对象
    return context;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.onLoad = function () { };
  _ctor.prototype.start = function () {
    var context = this; // 缓存当前上下文

    // 加载主场景的bundle
    s.default.loadBundle("mainScene", function () {
      // 加载主场景资源
      s.default.loadBundleRes("mainScene", "json/mainGameList", function (response) {
        context.listData = response.json; // 设置游戏列表数据
        // 确保context和节点存在后初始化游戏
        if (context && context.node) {
          context.initGame();
        }
      });
    }, true, true);

    // 执行其他初始化
    this._init();
    this.updateVideoCnt();
  };
  _ctor.prototype.OnBtnEnterInifinityMod = function () {
    var context = this; // 缓存当前上下文

    // 播放按钮声音
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 检查是否已开启畅玩模式
    if (Number($zqcc_OverallSystem.sers().localStorageSrv.get(d.default.changwanModel)) !== 0) {
      $zqcc_OverallSystem.sers().uiSrv.showMessage("已经开启畅玩模式！");
      this.changwanBtn.active = false; // 隐藏按钮
    } else {
      // 加载并展示视频广告
      $zqcc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(function () {
        window.LookCnt++; // 增加观看计数

        // 检查观看次数
        if (window.LookCnt >= 3) {
          // 增加用户的力量值
          $zqcc_OverallSystem.sers().userSrv.addPower(1999);
          // 更新本地存储
          $zqcc_OverallSystem.sers().localStorageSrv.set(d.default.infinityPowerModel, 1);
          $zqcc_OverallSystem.sers().localStorageSrv.set(d.default.infinityPowerDate, Date.now());
          $zqcc_OverallSystem.sers().localStorageSrv.set(d.default.changwanModel, 1);
          $zqcc_OverallSystem.sers().localStorageSrv.set(d.default.changwanModelDate, Date.now());
          // 发送更新游戏列表事件
          u.default.emit($GameEventType.EventType.UIEvent.updataGamelist);
        }
        // 更新视频观看次数
        context.updateVideoCnt();
      }, function () { }, null, {
        scene: "24小时无限畅玩",
        event: "24小时无限畅玩"
      }, "common_video");
    }
  };
  _ctor.prototype.updateVideoCnt = function () {
    // 更新提示字符串，显示观看次数
    this.tips.string = "（" + window.LookCnt + "/3）";

    // 设置畅玩按钮的活跃状态
    this.changwanBtn.active = Number($zqcc_OverallSystem.sers().localStorageSrv.get(d.default.changwanModel)) !== 1;
  };
  _ctor.prototype.initGame = function () {
    if (this.listData) {
      // 清空内容容器
      this.scrContent.removeAllChildren();

      // 遍历列表数据
      for (var key in this.listData) {
        if (Object.prototype.hasOwnProperty.call(this.listData, key)) {
          var itemData = this.listData[key];

          // 实例化列表项
          var newItem = cc.instantiate(this.item);
          newItem.parent = this.scrContent; // 设置父节点

          // 设置位置和层级
          newItem.x = 0;
          newItem.zIndex = 999 - itemData.zIndex;

          // 设置数据
          newItem.getComponent(h.default).setData(itemData);
        }
      }
    }
  };
  _ctor.prototype._init = function () {
    this.open();
  };
  _ctor.prototype.OnBtnConfirm = function () { };
  _ctor.prototype.OnBtnClose = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    this.onlyClose();
  };
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "item", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "scrContent", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "changwanBtn", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "tips", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(c.default);
exports.default = def_gameListNew;